const Actions = require('./actions');
const DB = require('app/db.js');

module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {
        loaded: false
    },

    onFetchDetail: function (params, cb) {
        let t = this;
        DB.Teacher.get_award_detail({
            schoolId: params.schoolId,
            awardId: params.awardId
        })
            .then((content) => {
                if (content.code == 1) {
                    let awardId = content.check.awardId;
                    let schoolId = content.check.schoolId;
                    content = content.data;

                    let { msg,title, list, studentName } = content;

                    let date = '';
                    let teachername = '';
                    for (let [key,item] of list.entries()) {
                        if (item.content.includes("时间")) {        
                            date = item.content.split(" ")[1] ;
                            delete list[key];
                        }
                        if (item.content.includes("老师")) {
                            teachername = item.content.split(" ")[1] ;
                            delete list[key];
                        }
                    }
                    Object.assign(this.data, { msg,date, teachername, title, list, studentName });
                    t.updateComponent();
                }
            })
            .catch(function (error) {

            });
    },

    updateComponent: function () {

        this.trigger(this.data);
    }
});
